package site.xuqing.autohelper.util;

import android.accessibilityservice.AccessibilityService;
import android.graphics.Path;
import android.view.accessibility.AccessibilityNodeInfo;

import java.util.List;

import site.xuqing.autohelper.StepScript;
import site.xuqing.autohelper.bean.StepBean;
import site.xuqing.autohelper.bean.StepInfoBean;
import site.xuqing.autohelper.listener.OnStepListener;

/**
 * 常规步骤实际执行类
 * 自定义步骤因为没有固定的操作方式，会回调到{@link StepScript#doStep(AccessibilityService, StepBean, StepExecutor, OnStepListener)}方法，需要用户自行组合
 * @author XuQing
 */
public interface StepExecutor {
    /**
     * 单击
     *
     * @param node AccessibilityNodeInfo
     * @throws Exception 异常
     */
    void singleTap(AccessibilityNodeInfo node) throws Exception;
    
    /**
     * 双击
     *
     * @param node AccessibilityNodeInfo
     * @throws Exception 异常
     */
    void doubleTap(AccessibilityNodeInfo node) throws Exception;
    
    /**
     * 长按
     *
     * @param node AccessibilityNodeInfo
     * @throws Exception 异常
     */
    void longTap(AccessibilityNodeInfo node) throws Exception;
    
    /**
     * 已node的边界计算出node的中心并单击
     *
     * @param service AccessibilityService
     * @param node    AccessibilityNodeInfo
     * @throws Exception 异常
     */
    void rectSingleTap(AccessibilityService service, AccessibilityNodeInfo node) throws Exception;
    
    /**
     * 已node的边界计算出node的中心并长按
     *
     * @param service AccessibilityService
     * @param node    AccessibilityNodeInfo
     * @throws Exception 异常
     */
    void rectLongTap(AccessibilityService service, AccessibilityNodeInfo node) throws Exception;
    
    /**
     * 返回&退出
     *
     * @param service AccessibilityService
     * @throws Exception 异常
     */
    void back(AccessibilityService service) throws Exception;
    
    /**
     * 查找node中匹配StepBean信息的node
     *
     * @param node     需要查找的AccessibilityNodeInfo
     * @param stepBean 包含需要查找的信息的StepBean对象
     * @return AccessibilityNodeInfo 返回查找到的node
     * @throws Exception 异常
     */
    AccessibilityNodeInfo findStepInfoNode(AccessibilityNodeInfo node, StepBean stepBean) throws Exception;
    
    /**
     * 查找note中匹配指定信息的node
     *
     * @param node           需要查找的AccessibilityNodeInfo
     * @param stepInfo       指定需要查找的信息
     * @param stepInfoParent 指定需要查找的信息的父信息
     * @param stepInfoChild  指定需要查找的信息的子信息
     * @return AccessibilityNodeInfo 返回查找到的node
     * @throws Exception 异常
     */
    AccessibilityNodeInfo findStepInfoNode(AccessibilityNodeInfo node, StepInfoBean stepInfo, StepInfoBean stepInfoParent, StepInfoBean stepInfoChild) throws Exception;
    
    /**
     * 查找note中匹配指定信息的node集合
     *
     * @param node     需要查找的AccessibilityNodeInfo
     * @param stepInfo 指定需要查找的信息
     * @return AccessibilityNodeInfo 返回查找到的node集合
     * @throws Exception 异常
     */
    List<AccessibilityNodeInfo> findStepInfoNodes(AccessibilityNodeInfo node, StepInfoBean stepInfo) throws Exception;
    
    /**
     * 执行手势
     *
     * @param service  AccessibilityService
     * @param p        手势路径
     * @param duration 手势执行时长
     * @throws Exception 异常
     */
    void doGesture(AccessibilityService service, Path p, Long duration) throws Exception;
    
    /**
     * 查找note中匹配className的node集合
     *
     * @param node      需要查找的AccessibilityNodeInfo
     * @param className ClassName
     * @param result    查找到的note集合
     * @throws Exception 异常
     */
    void findNodesByClassName(AccessibilityNodeInfo node, String className, List<AccessibilityNodeInfo> result) throws Exception;
    
    /**
     * 查找note中匹配text的node集合
     *
     * @param node   需要查找的AccessibilityNodeInfo
     * @param text   TEXT
     * @param result 查找到的note集合
     * @throws Exception 异常
     */
    void findNodesByText(AccessibilityNodeInfo node, String text, List<AccessibilityNodeInfo> result) throws Exception;
    
    /**
     * 打印note信息
     *
     * @param node 需要打印的AccessibilityNodeInfo
     * @throws Exception 异常
     */
    void printNodes(AccessibilityNodeInfo node) throws Exception;
    
    /**
     * 复制
     *
     * @param service  AccessibilityService
     * @param textNode 文本类型的AccessibilityNodeInfo
     * @throws Exception 异常
     */
    void copy(AccessibilityService service, AccessibilityNodeInfo textNode) throws Exception;
    
    /**
     * 粘贴剪切板中的内容（需要先调copy使剪切板有值）
     *
     * @param editNode 输入框类型的AccessibilityNodeInfo
     * @throws Exception 异常
     */
    void paste(AccessibilityNodeInfo editNode) throws Exception;
    
    /**
     * 粘贴指定内容
     *
     * @param editNode  输入框类型的AccessibilityNodeInfo
     * @param pasteText 需要粘贴的内容
     * @throws Exception 异常
     */
    void paste(AccessibilityNodeInfo editNode, String pasteText) throws Exception;
    
    /**
     * 查找可点击的父note
     *
     * @param child 子note AccessibilityNodeInfo
     * @return AccessibilityNodeInfo 查找到的note
     * @throws Exception 异常
     */
    AccessibilityNodeInfo findClickNode(AccessibilityNodeInfo child) throws Exception;
    
    /**
     * 查找可长按的父note
     *
     * @param child 子note AccessibilityNodeInfo
     * @return AccessibilityNodeInfo 查找到的note
     * @throws Exception 异常
     */
    AccessibilityNodeInfo findLongClickNode(AccessibilityNodeInfo child) throws Exception;
}
